package com.ruoyi.hr.controller.hr.changemanage.trialchangejust;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.hr.domain.Authority;
import com.ruoyi.hr.service.AuthorityService;
import com.ruoyi.hr.service.changemanage.trialchange.TrialChangeService;
import com.ruoyi.hr.service.changemanage.trialchangejust.TrialChangeJustService;
import com.ruoyi.hr.util.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author zeo
 * @explain 试用转正登记
 * @date 2020/3/11
 */
@Controller
@RequestMapping("/changeManage/TrialChangeJust")
public class TrialChangeJustController extends BaseController {

    @Autowired
    AuthorityService authorityService;

    @Autowired
    TrialChangeJustService trialChangeJustService;

    @Autowired
    TrialChangeService trialChangeService;

    private String prefix = "hr/changemanage/trialchangejust";

    /**
     * 跳转分页页面
     */
    @GetMapping()
    public String trialChangeJust() {
        return prefix + "/trialChangeJust";
    }

    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map map) {
        Authority authority = authorityService.findAuthorAndIsAdmin();
        startPage();
        return getDataTable(trialChangeJustService.findTrialJustChangeListData(map, authority));
    }

    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        mmap.put("editTrialJustEmp", trialChangeJustService.getTrialJustEmpById(id));
        return prefix + "/editTrialJustEmp";
    }

    @RequestMapping("/edit")
    @ResponseBody
    public AjaxResult edit(@RequestParam Map map){
        return toAjax(trialChangeJustService.editTrialJustEmp(map));
    }

    @GetMapping("/add")
    public String addTrialChangeJustEmp() {
        return prefix + "/addTrialChangeJustEmp";
    }

    @RequestMapping("/findTrialChangeJustEmp")
    @ResponseBody
    public TableDataInfo findTrialChangeJustEmp(@RequestParam Map map) {
        Authority authority = authorityService.findAuthorAndIsAdmin();
        startPage();
        return getDataTable(trialChangeJustService.findTrialChangeJustEmp(map, authority));
    }


    /**
     * 执行添加员工存储过程
     */
    @PostMapping("/addTrialChangeJustEmp")
    @ResponseBody
    public BaseResult addTrialChangeJustEmp(String allEid) {
        return trialChangeJustService.addTrialChangeJustEmp(allEid);
    }

    @RequestMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids){
        return toAjax(trialChangeService.removeData(ids));
    }

    @GetMapping("/history")
    public String history(){
        return prefix + "/history";
    }

    @RequestMapping("/historyList")
    @ResponseBody
    public TableDataInfo historyList(@RequestParam Map map) {
        Authority authority = authorityService.findAuthorAndIsAdmin();
        startPage();
        return getDataTable(trialChangeJustService.historyList(map, authority));
    }
}
